/* Project ir_R01
Infrared controller PIC16F628A
*/
#include <pic.h>
__CONFIG(
INTIO
& UNPROTECT
& LVPDIS
& BORDIS
& MCLRDIS
& WDTDIS
& PWRTEN
);
__IDLOC(628A);
#define IR RB3
#define LED RB4
#define N 8
const unsigned char sig[N] = {
0,0,1,0,1,0,0,0
};
void main(void){
unsigned char i,j,m;
unsigned char t[9],s[8];
PORTB = 0;
TRISB = 0b00001000;
PORTA = 0;
TRISA = 0b00000000;
OPTION = 0b10000100;
while(1){
TMR0 = 0;
while(TMR0 < 100){
if(IR) TMR0 = 0;
}
while(IR == 0);
while(IR);
for(i = 0; i < 9; i++){
while(IR == 0);
TMR0 = 0;
while(IR && (TMR0 < 100));
t[i] = TMR0;
if(t[i] >= 80) break;
}
m = 0;
for(i = 0; i < N; i++){
if(t[i] < 30) s[i] = 0;
else s[i] = 1;
if(s[i] = sig[i]) m = m + 1;
}
if(m = N) LED = 1;
else LED = 0;
for(j = 0; j < 25; j++){
TMR0 = 0;
while(TMR0 < 255);
}
LED = 0;
}
}